package bawei.com.adapter;


import android.content.Context;

import android.support.v7.widget.RecyclerView;



import android.util.Log;

import android.view.LayoutInflater;

import android.view.View;
import android.view.ViewGroup;

import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import bawei.com.bilibili.R;
import bawei.com.model.bean.RegionTypeDetailsBean;

/**
 * 类描述:
 * 作者：cwm
 * 时间:2017/3/21 20:37
 * 邮箱:18310832074@163.com
 */

public class RegionTypeDetailsAdapter extends RecyclerView.Adapter{


    private Context context;
    private List<RegionTypeDetailsBean.DataBean.NewBean> newX;
    List<RegionTypeDetailsBean.DataBean.RecommendBean> recommend;


    public RegionTypeDetailsAdapter(Context context, List<RegionTypeDetailsBean.DataBean.NewBean> newX, List<RegionTypeDetailsBean.DataBean.RecommendBean> recommend) {
        this.context = context;
        this.newX = newX;
        this.recommend = recommend;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        if(viewType==1){
            return new RTViewHolder(LayoutInflater.from(context).inflate(R.layout.item_zuire,parent,false));

        }else {
            return new RViewHolder(LayoutInflater.from(context).inflate(R.layout.item_video_strip,parent,false));
        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        if(holder instanceof RTViewHolder){

           RTViewHolder viewHolder= (RTViewHolder) holder;
            if(position==0){
            viewHolder.mVideoTitle.setText("最热视频");
            }else
            if(position==5){
                viewHolder.mVideoTitle.setText("最新视频");
            }
        }else
        if(holder instanceof RViewHolder){
            RViewHolder viewHolder= (RViewHolder) holder;

                if(position==1){
                    Log.i("TAG1", "onBindViewHolder: "+recommend.get(0).getName());
                viewHolder.mUserName.setText(recommend.get(0).getName());
                    viewHolder.mVideoTitle.setText(recommend.get(0).getTitle());
                    Glide.with(context)
                            .load(recommend.get(0).getCover())
                            .into(viewHolder.mVideoImg);
                    viewHolder.mVideoPlayNum.setText(recommend.get(0).getPlay()+"");
                    viewHolder.mVideoReviewCount.setText(recommend.get(0).getParam()+"");
                }else
                if(position==2){
                    viewHolder.mUserName.setText(recommend.get(1).getName());
                    viewHolder.mVideoTitle.setText(recommend.get(1).getTitle());
                    Glide.with(context)
                            .load(recommend.get(1).getCover())
                            .into(viewHolder.mVideoImg);
                    viewHolder.mVideoPlayNum.setText(recommend.get(1).getPlay()+"");
                    viewHolder.mVideoReviewCount.setText(recommend.get(1).getParam()+"");
                }
                else
                if(position==3){
                    viewHolder.mUserName.setText(recommend.get(2).getName());
                    viewHolder.mVideoTitle.setText(recommend.get(2).getTitle());
                    Glide.with(context)
                            .load(recommend.get(2).getCover())
                            .into(viewHolder.mVideoImg);
                    viewHolder.mVideoPlayNum.setText(recommend.get(2).getPlay()+"");
                    viewHolder.mVideoReviewCount.setText(recommend.get(2).getParam()+"");
                }
                else
                if(position==4){
                    viewHolder.mUserName.setText(recommend.get(3).getName());
                    viewHolder.mVideoTitle.setText(recommend.get(3).getTitle());
                    Glide.with(context)
                            .load(recommend.get(3).getCover())
                            .into(viewHolder.mVideoImg);
                    viewHolder.mVideoPlayNum.setText(recommend.get(3).getPlay()+"");
                    viewHolder.mVideoReviewCount.setText(recommend.get(3).getParam()+"");
                }
            else {

                viewHolder.mUserName.setText(newX.get(position-6).getName());
                viewHolder.mVideoTitle.setText(newX.get(position-6).getTitle());
                Glide.with(context)
                        .load(newX.get( position-6).getCover())
                        .into(viewHolder.mVideoImg);

                viewHolder.mVideoPlayNum.setText(newX.get(position-6).getPlay()+"");
                viewHolder.mVideoReviewCount.setText(newX.get(position-6).getParam()+"");
            }
        }

    }

    @Override
    public int getItemViewType(int position) {

        if(position==0||position==5){

            return 1;
        }else {

            return 2;
        }

    }

    @Override
    public int getItemCount() {
        return newX.size()+recommend.size();
    }
    class RViewHolder extends RecyclerView.ViewHolder{

        ImageView mVideoImg;
        TextView mVideoTitle;
        TextView mVideoPlayNum;
        TextView mVideoReviewCount;
        TextView mUserName;

        public RViewHolder(View itemView) {
            super(itemView);

            mVideoImg = (ImageView) itemView.findViewById(R.id.item_img);
            mVideoTitle = (TextView) itemView.findViewById(R.id.item_title);
            mVideoPlayNum = (TextView) itemView.findViewById(R.id.item_play);
            mVideoReviewCount = (TextView) itemView.findViewById(R.id.item_review);
            mUserName = (TextView) itemView.findViewById(R.id.item_user_name);
        }
    }
    class RTViewHolder extends RecyclerView.ViewHolder{

        TextView mVideoTitle;
        public RTViewHolder(View itemView) {
            super(itemView);
            mVideoTitle = (TextView) itemView.findViewById(R.id.zuire_t);
        }
    }
}
